package com.ibm.workplace.wcm.cqplugin.ui.actions;

import java.util.*;

import org.eclipse.jface.viewers.*;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.ui.actions.*;

import com.ibm.workplace.wcm.cqplugin.*;

public class CopyBugInformationAction extends SelectionProviderAction {

    public CopyBugInformationAction(ISelectionProvider provider) {
        super(provider, "Copy Defect Information");
    }

    public void selectionChanged(IStructuredSelection selection) {
        setEnabled(selection != null && selection.size() > 0);
    }

    public void run() {
        IStructuredSelection ss = (IStructuredSelection) getSelection();
        /*IBugInfo[] bugs = new IBugInfo[ss.size()];
        String defectNumbers = "";
        for (Iterator it = ss.iterator(); it.hasNext();) {
            IBugInfo bi = (IBugInfo) it.next();
            if (bi != null && bi.getId() != null && bi.getDescription() != null) {
                defectNumbers = defectNumbers + bi.getId() + " - " + bi.getDescription() + System.getProperty("line.separator");
            }
        }        
        defectNumbers = defectNumbers.trim();

        Shell shell = getSelectionProvider() instanceof TableViewer ? ((TableViewer) getSelectionProvider()).getTable().getShell() : PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

        Clipboard clipboard = new Clipboard(shell.getDisplay());
        TextTransfer textTransfer = TextTransfer.getInstance();
        clipboard.setContents(new String[] { defectNumbers }, new Transfer[] { textTransfer });
        clipboard.dispose();*/
    }

}
